package com.sky.controller.admin;

import com.sky.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

/**
 * @author wfyn
 */
@RestController("adminShopController")
@RequestMapping("/admin/shop")
@Api(tags = "店铺操作接口")
public class ShopController {



    public  static  final  String KEY ="SHOP_STATUS";
    @Autowired
    private  RedisTemplate redisTemplate;


    /**
     * 修改店铺状态
     * @param status 营业中：1  打烊中：0
     */
    @PutMapping("/{status}")
    @ApiOperation("修改店铺状态")
    public Result updateShopStatus(@PathVariable("status") Integer status) {
        redisTemplate.opsForValue().set(KEY, status);
        return Result.success("修改店铺状态成功");
    }

    /**
     * 获取营业状态
     * @return 营业中：1  打烊中：0
     */

    @GetMapping("/status")
    @ApiOperation("获取营业状态")
    public Result<Integer> getStatus() {
        Integer status = (Integer)redisTemplate.opsForValue().get(KEY);
        return Result.success(status);
    }
}
